package com.huirui.server.controller.admin;

import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.HotSalesRankingVo;
import com.huirui.server.service.HotSalesRankingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/ranking")
@Slf4j
@Validated
@Tag(name = "热销商品管理", description = "小程序热销商品管理")
public class HotSalesRankingController {

    @Resource
    private HotSalesRankingService hotSalesRankingService;

    @GetMapping("/list")
    @Operation(summary = "查询热销商品列表")
    public Result<PageResult<HotSalesRankingVo>> listHotSalesRanking(
            @RequestParam(value = "keyword", required = false) String keyword,
            Long page,
            Long pageSize
    ) {
        PageResult<HotSalesRankingVo> res = hotSalesRankingService.listHotSalesRanking(keyword, page, pageSize);
        return Result.success(res);
    }

    @PostMapping("/add")
    @Operation(summary = "新增热销商品条目")
    public Result<Void> addHotSalesRanking(Long categoryId, Long status) {
        hotSalesRankingService.addHotSalesRanking(categoryId, status);
        return Result.success();
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除热销榜单项")
    public Result<Void> deleteHotSalesRanking(@RequestParam("categoryId") Long categoryId) {
        hotSalesRankingService.deleteHotSalesRanking(categoryId);
        return Result.success();
    }

    @PutMapping("/update")
    @Operation(summary = "更新热销条目")
    public Result<Void> updateHotSalesRanking(Long categoryId, Long status) {
        hotSalesRankingService.updateHotSalesRanking(categoryId, status);
        return Result.success();
    }


}
